package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark3Binding;
import com.water.camera.util.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark3 extends BaseMark {

    LayoutWatermark3Binding binding;

    public Mark3(@NonNull Context context) {
        super(context);
    }

    public Mark3(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark3(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark3Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
        } else {
            binding = LayoutWatermark3Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
        if (type == 0) {
            hideView(binding.binding11, binding.binding13);
        }
    }

    @Override
    public void update() {
        setText(binding.binding2, "title3", "日常保洁", binding.binding1);
        setText(binding.binding4, "time3", "13:30", binding.binding3);
        setTime(binding.binding4, new SimpleDateFormat("HH:mm"));
        if (!setTime(binding.binding5, new SimpleDateFormat("yyyy.MM.dd"))) {
            binding.binding5.setText("2023.03.09");
        }
        setText(binding.binding8, "content3", binding.binding7);
        setText(binding.binding10, "area3", binding.binding9);
        setText(binding.binding12, "fuzeren3", binding.binding11);
        setText(binding.binding14, "didan3", "在这里", binding.binding13);
        setText(binding.binding16, "beizhu3", binding.binding15);
        setText(binding.binding18, "house3", binding.binding17);
        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title3", "标题"));
        list.add(new EditItem("time3", "时间", true));
        list.add(new EditItem("content3", "工作内容"));
        list.add(new EditItem("area3", "工作区域"));
        list.add(new EditItem("fuzeren3", "负责人"));
        list.add(new EditItem("didian3", "地点"));
        list.add(new EditItem("beizhu3", "备注"));
        list.add(new EditItem("house3", "单位名称"));
        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding4, new SimpleDateFormat("HH:mm"));
            setTime(binding.binding5, new SimpleDateFormat("yyyy.MM.dd"));
        } else {
            super.onValueChange(item);
        }
    }
}
